package edu.ut.ece382c.valloy.translator.tester;

import javax.swing.JTextArea;

public class TestLogger {
	private boolean toConsole;
	private boolean toString;
	private boolean toControl;
	private StringBuilder out;
	private JTextArea control;

	public TestLogger(StringBuilder stringBuilder) {
		this.toString = true;
		this.out = stringBuilder;
	}
	
	public TestLogger() {
		this.toString = false;
		this.out = new StringBuilder("");
		this.toConsole= true;
	}
	
	public TestLogger(JTextArea jTextControl) {
		this.toString = false;
		this.toConsole= false;
		this.control = jTextControl;
	}
	
	public void enableConsoleOut (boolean enable){
		toConsole = enable;
	}
	
	public void enableControlOut (boolean enable){
		toControl = enable;
	}
	
	public void setControlOut (JTextArea controlOut){
		toControl = true;
		control = controlOut;
	}
	
	public String append(String text){
		if (toConsole)
			System.out.print(text);
		if (toString)
			out.append(text).toString();
		if (toControl)
			control.append(text);
		return out.toString();
	}
	public String appendLn(String text){
		if (toConsole)
			System.out.print(text + "\n");
		if (toString)
			out.append(text + "\n").toString();
		if (toControl)
			control.append(text + "\n");

		return out.toString();
	}
	
	public String flush(){
		if (toConsole)
			System.out.flush();
		return out.toString();
	}
}
